/*
 * HttpServiceUtil.h
 *
 *  Created on: 2019年11月29日
 *      Author: terry
 */

#ifndef HTTPSERVICEUTIL_H_
#define HTTPSERVICEUTIL_H_

#include "HttpServer.h"
#include "StringMap.h"
#include <vector>

#include "json/json.h"


typedef std::pair< std::string, bool >	EnabledItem;
typedef std::vector< EnabledItem >		EnabledItems;

typedef std::vector< int >  IntArray;
typedef std::vector< int64_t >  Int64Array;


class HttpServiceUtil
{
public:
	HttpServiceUtil();
	virtual ~HttpServiceUtil();

	static bool parseJson(const char* str, size_t len, Json::Value& json);
	static bool bodyAsJson(HttpRequest& request, Json::Value& json);

	static int parseEnabled(HttpRequest& request, EnabledItems& items);

	static int getSearchParams(HttpRequest& request, int& offset);

	static int parseIds(HttpRequest& request, StringArray& ids);
    static int parseIds(HttpRequest& request, IntArray& ids);
	static int parseIds(HttpRequest& request, Int64Array& ids);

    static bool parseBody(HttpRequest& request, StringArray& strList);

	static bool checkGet(HttpRequest& request, const char* name, const char* optName, int& value);

	static bool getRemoteAddr(HttpServer* server, HttpRequest& request, std::string& ip, int& port);

};

#endif /* HTTPSERVICEUTIL_H_ */
